/**
 * This file is part of Idegen, the application to create IDE project files.
 *
 * @copyright Copyright (c) 2011-2012, Walter Tamboer http://waltertamboer.nl
 * @file Idegen/Idegen/IdegenProjectFilter.hpp
 */

#ifndef IDEGEN_IDEGEN_IDEGENPROJECTFILTER_HPP
#define IDEGEN_IDEGEN_IDEGENPROJECTFILTER_HPP

namespace Idegen
{
	struct IdegenProjectFile;
	class IdegenProjectFilter;
	
	/** A list with all the files. */
	typedef std::vector< IdegenProjectFile* > ProjectFileList;

	/** A list containing project filters. */
	typedef std::vector< IdegenProjectFilter* > ProjectFilterList;

	/** A list with all the project filter names. */
	typedef std::vector< std::string> ProjectFilterNameList;

	/** A project filter. */
	class IdegenProjectFilter
	{
	public:
		/**
		 * Initializes a new instance of this class.
		 *
		 * @param[in] name The name of this filter.
		 */
		IdegenProjectFilter( const std::string& name );

		/**
		 * Initializes a new instance of this class.
		 *
		 * @param[in] name The name of this filter.
		 * @param[in] parent The parent of this filter.
		 */
		IdegenProjectFilter( const std::string& name, IdegenProjectFilter* parent );

		/** Cleans up all the resources used by this class. */
		~IdegenProjectFilter();

		/**
		 * Gets a list with all the files in this source set.
		 *
		 * @param[in] allFiles Whether or not to return the children as well.
		 * @return Returns the files.
		 */
		ProjectFileList GetFiles( bool allFiles ) const;

		/**
		 * Gets the name of this filter.
		 *
		 * @return Returns a string containing the name of the filter.
		 */
		std::string GetName() const;

		/**
		 * Gets the full name of this filter.
		 *
		 * @return Returns a string containing the name of the filter.
		 */
		std::string GetFullName() const;

		/**
		 * Adds a file to this filter.
		 *
		 * @param[in] file The file to add.
		 * @return void
		 */
		virtual void AddFile( IdegenProjectFile* file );

		/**
		 * Adds a filter as a child filter to this. When it already exists; the existing one is returned.
		 *
		 * @param[in] name The name of the filter to add.
		 * @param[in] parentFilter The parent filter to add the filter to.
		 * @return Returns a pointer to the created or found filter.
		 */
		IdegenProjectFilter* AddFilter( const std::string& name, IdegenProjectFilter* parentFilter );

		/**
		 * Tries to find the filter with the given name.
		 *
		 * @param[in] name The name of the filter to find.
		 * @return Returns the filter that has been found or NULL if it doesn't exist.
		 */
		IdegenProjectFilter* FindFilter( const std::string& name ) const;

		/**
		 * Gets all the filters that belong to this filter.
		 *
		 * @return Returns a list with all the filters that belong to this filter.
		 */
		ProjectFilterList GetFilters() const;

	private:
		/**
		 * Parses the given path into filters.
		 *
		 * @param[in] path The path of the filters.
		 * @param[out] nameList Stores the parsed names in here.
		 * @return Returns true when names are parsed; false otherwise.
		 */
		bool ParseFilterNames( const std::string& path, ProjectFilterNameList& nameList );

		/** The name of this filter. */
		std::string m_Name;

		/** The parent of this filter. */
		IdegenProjectFilter* m_Parent;

		/** A list with all the filters in this filter. */
		ProjectFilterList m_Filters;

		/** A list with all the files that this source set has. */
		ProjectFileList m_Files;
	};
}

#endif
